package com.zc.im.controller;


import com.alibaba.fastjson.JSONObject;
import com.zc.im.model.user.ZcAdminUser;
import com.zc.im.service.user.ZcAdminUseService;
import com.zc.im.util.JsonUtils;
import com.zc.im.util.ResponseJson;
import com.zc.im.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 客服分配表
 * Created by wangcc on 2017/7/22.
 */
@Controller
@RequestMapping( "/zcadminuse")
public class ZcAdminUserController {

    @Autowired
    private ZcAdminUseService zcAdminUseService;


    /**
     * 添加用户
     * @param zcAdminUseId
     * @return
     */
    @RequestMapping(value = "/insertconstormer")
    @ResponseBody
    public ResponseJson insertCustomerService(String zcAdminUseId) {
        ResponseJson responseJson = new ResponseJson();
        if (StringUtils.isEmpty(zcAdminUseId)) {
            return responseJson;
        }
        ZcAdminUser jsonType = JsonUtils.strToClass(zcAdminUseId, ZcAdminUser.class);
        Integer zcAdminUseServiceKey =  zcAdminUseService.saveCoustormerService(jsonType);
        Map<String ,Object > dataMap = new HashMap<>();
        dataMap.put("key",zcAdminUseServiceKey);
        responseJson.setDataMap(dataMap);
        return responseJson;
    }


    /**
     * 删除客服
     */
    @RequestMapping(value = "/deletecustomer")
    @ResponseBody
    public ResponseJson deleteCustomerService(String zcAdminUserId) {
        ResponseJson responseJson = new ResponseJson();
        if (StringUtils.isEmpty(zcAdminUserId)) {
            return responseJson;
        }
        JSONObject jsonType = JsonUtils.strToJsonObj(zcAdminUserId);
        Integer zcAdminUseServiceKey =zcAdminUseService
                .delectCoustormerService(Integer.parseInt(jsonType.getString("zcAdminUseId")));
        Map<String, Object > dataMap = new HashMap<>();
        dataMap.put("key",zcAdminUseServiceKey);
        responseJson.setDataMap(dataMap);
        return responseJson;
    }


    @RequestMapping(value = "/findPichead")
    @ResponseBody
    public ResponseJson findPichead(String customerId) {
        ResponseJson responseJson =  new ResponseJson();
        if (StringUtils.isEmpty(customerId)) {
            return responseJson;
        }
        JSONObject jsonObject = JsonUtils.strToJsonObj(customerId);
        ZcAdminUser  zcAdminUser = zcAdminUseService.findZcAdminUser(Integer.parseInt(jsonObject.getString("customerId")));
        Map<String ,Object> dataMap =  new HashMap<>();
        dataMap.put("zcAdminUser" ,JsonUtils.objToStr(zcAdminUser));
        responseJson.setDataMap(dataMap);
        return responseJson;
    }
}
